require(['monitor', 'gaodeMap'], function () {
    //高德地图对象
	var bus=null;
    var map = new MapGaoDe(107.49023438,36.24427318, 2);
    //左侧选中的车辆
	var selectCarId="";
	$('#iCenter').css({
        width : $(window).width() - 695,
        height : 385
	});

    $('#monitor').monitor({
        canId: '15',
        callback: function (data) {
        	loadData(data);
        },
        clearData: function () {
        	loadData({});
        }
    });
    
    function loadData(data){
    	//经纬度
		if (data.latitude && data.longitude) {
			if (bus) {
				bus.clear();
			}
			map.setMapLevel(14);
			bus = new Bus(map, '', data.longitude, data.latitude);
			bus.setDirection(data.direction);
			bus.show();
			map.mapMoveTo(data.longitude, data.latitude);
		}
        $("#capacitaClass").setViewData(data);
        $("#isOnLine").setView(data.isOnLine, [
            {value: 0,text: '充电'},
            {value: 1,text: '放电'},
            {value: 2,text: '未充放电'}
        ]);
    }
    
    $('#querySoloCapacitor').on('click',function(){
    	if($('#monitor').monitor('getStatus')=='monitor'){
			var command = "{canId:'20',carId:'" + selectCarId + "',timeSpan:1,interval:0}";
			$.fn.monitor.command(command,{callback:function(data){
				var modAr = data.moduleNoList.split("/");
				var volAr = data.voltageList.split("/");
				var tmprtAr = data.temperatureList.split("/");
				var len = modAr.length-1;
                $("#soloCapacitor tr:not(:first)").remove();
				var trStr = "";
				for(var i=0;i<len;i++){
                    trStr += "<th class='fw-b fs-14' >"+(i+1)+"</th>"
					+"<td class='fw-b fs-14'>"+volAr[i]+"</td>"
					+"<td class='fw-b fs-14'>"+tmprtAr[i]+"</td>";
					if((i+1)%2==0 || i==(len-1)){
                        var $currentRow=$("#soloCapacitor tr").eq(-1);
                        var $row = $("<tr>"+trStr+"</tr>");
                        $currentRow.after($row);
                        trStr = "";
                    }
				}
            }});
    	}
    	else{
    		$.messager.alert("提示","请先下发电容监控命令。","info");
    	}
	});

	//左侧树
	commonFun.leftTreeNodeClickObj['carChange'] = function(event,treeId, treeNode) {
		selectCarId=treeNode.id;
		$("#h3_title").html(treeNode.name + " 电容实时监控");
		if (treeNode.type === "CAR" && treeNode.typeDetail == 'CAT00002' && treeNode.typeDetail == 'CAT00003') {
			$("#capacitorTitle").text(treeNode.name + " 电容实时监控");
		} else {//传统车
			$("#capacitorTitle").text("");
		}
	};
});